#!/bin/bash

# 设置颜色输出
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # 无色

echo -e "${YELLOW}====================================================${NC}"
echo -e "${YELLOW}    异构并行矩阵乘法性能测试套件    ${NC}"
echo -e "${YELLOW}====================================================${NC}"

module purge
module load compiler/rocm/dtk-23.10
module load compiler/gcc/9.3.0 

echo "=== Environment ==="
echo "HIP_PATH: ${HIP_PATH}"
echo "ROCM_PATH: ${ROCM_PATH}"
echo ""

# 2. Compile Code
echo "--- Compiling Code ---"
make clean
make -j HIPCC=hipcc

# 创建结果目录
mkdir -p results
mkdir -p results/plots
mkdir -p results/nonsquare
mkdir -p results/nonsquare/plots
mkdir -p results/threadscan
mkdir -p results/threadscan/plots
mkdir -p results/report

# 1. 运行方阵测试
echo -e "${BLUE}[1/5] 正在运行方阵性能测试...${NC}"
bash ./batch_test.sh

# 2. 运行非方阵测试
echo -e "${BLUE}[2/5] 正在运行非方阵性能测试...${NC}"
bash ./batch_test_nonsquare.sh

# 4. 生成方阵性能图表
echo -e "${BLUE}[3/4] 正在生成方阵性能可视化图表...${NC}"
python3 plot_performance.py

# 5. 生成非方阵性能图表
echo -e "${BLUE}[4/4] 正在生成非方阵性能可视化图表...${NC}"
python3 plot_nonsquare_performance.py

echo -e "${GREEN}所有测试完成！${NC}"